package com.office.web.controller.system;

import java.util.List;
import java.util.Map;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.office.common.annotation.Log;
import com.office.common.core.controller.BaseController;
import com.office.common.core.domain.AjaxResult;
import com.office.common.enums.BusinessType;
import com.office.system.domain.FinanceIncome;
import com.office.system.service.IFinanceIncomeService;
import com.office.common.utils.poi.ExcelUtil;
import com.office.common.core.page.TableDataInfo;

/**
 * 收入记录Controller
 * 
 * @author 数字牧马人
 */
@RestController
@RequestMapping("/system/finance/income")
public class FinanceIncomeController extends BaseController
{
    @Autowired
    private IFinanceIncomeService financeIncomeService;

    /**
     * 查询收入记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:finance:income:list')")
    @GetMapping("/list")
    public TableDataInfo list(FinanceIncome financeIncome)
    {
        startPage();
        List<FinanceIncome> list = financeIncomeService.selectFinanceIncomeList(financeIncome);
        return getDataTable(list);
    }

    /**
     * 导出收入记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:finance:income:export')")
    @Log(title = "收入记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FinanceIncome financeIncome)
    {
        List<FinanceIncome> list = financeIncomeService.selectFinanceIncomeList(financeIncome);
        ExcelUtil<FinanceIncome> util = new ExcelUtil<FinanceIncome>(FinanceIncome.class);
        util.exportExcel(response, list, "收入记录数据");
    }

    /**
     * 获取收入记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:finance:income:query')")
    @GetMapping(value = "/{incomeId}")
    public AjaxResult getInfo(@PathVariable("incomeId") Long incomeId)
    {
        return success(financeIncomeService.selectFinanceIncomeByIncomeId(incomeId));
    }

    /**
     * 新增收入记录
     */
    @PreAuthorize("@ss.hasPermi('system:finance:income:add')")
    @Log(title = "收入记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FinanceIncome financeIncome)
    {
        return toAjax(financeIncomeService.insertFinanceIncome(financeIncome));
    }

    /**
     * 修改收入记录
     */
    @PreAuthorize("@ss.hasPermi('system:finance:income:edit')")
    @Log(title = "收入记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FinanceIncome financeIncome)
    {
        return toAjax(financeIncomeService.updateFinanceIncome(financeIncome));
    }

    /**
     * 删除收入记录
     */
    @PreAuthorize("@ss.hasPermi('system:finance:income:remove')")
    @Log(title = "收入记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{incomeIds}")
    public AjaxResult remove(@PathVariable Long[] incomeIds)
    {
        return toAjax(financeIncomeService.deleteFinanceIncomeByIncomeIds(incomeIds));
    }

    /**
     * 统计收入金额
     */
    @PreAuthorize("@ss.hasPermi('system:finance:income:query')")
    @GetMapping("/amount")
    public AjaxResult getAmount(FinanceIncome financeIncome)
    {
        return success(financeIncomeService.selectIncomeAmount(financeIncome));
    }

    /**
     * 按分类统计收入
     */
    @PreAuthorize("@ss.hasPermi('system:finance:income:query')")
    @GetMapping("/category")
    public AjaxResult getCategory(FinanceIncome financeIncome)
    {
        List<Map<String, Object>> list = financeIncomeService.selectIncomeByCategory(financeIncome);
        return success(list);
    }
} 